package com.bz.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bz.common.UserConfig;
import com.bz.dao.ContactsDao;
import com.bz.entity.ContactsEntity;
import com.bz.entity.UserEntity;
import com.bz.service.IContactsService;

@Service
public class ContactsServiceImpl implements IContactsService {

    @Autowired
    private ContactsDao contactsDao;

    @Override
    public ContactsEntity get() {
        return contactsDao.selectOne(null);
    }

    @Override
    public void edit(ContactsEntity data) {
        ContactsEntity db = contactsDao.selectOne(null);
        UserEntity lu = UserConfig.getLoginUser();
        data.setUpdateBy(lu.getUsername());
        if (null == db) {
            data.setCreateBy(lu.getUsername());
            data.setCreateDate(new Date());
            contactsDao.insert(data);
        } else {
            contactsDao.updateById(data);
        }
    }

}
